package com.ceba.test.base.dbdata.modules;

import org.apache.commons.lang.StringUtils;
import com.ceba.base.dbdata.DataTableObject;
import com.ceba.base.dbdata.MysqlUtils;
public class ConfigDb {

	public static void init() throws Exception{
		//9-start
		DataTableObject config=new DataTableObject("config");
		config.addField("KEY", "varchar(255)", "NOT NULL", "", "true");
		config.addField("VALUE", "text", "DEFAULT NULL", "", "false");
		config.addField("REMARK", "text", "DEFAULT NULL", "", "false");
		MysqlUtils.syncTableStructure(config);
		
		//添加表记录
		MysqlUtils.initConfig("config","ALLOW_LOGIN_DATE", "", "");
		MysqlUtils.initConfig("config","ALLOW_SIGN_NUM", "MjAwMDA=", "");
		MysqlUtils.initConfig("config","ALL_SIGNCOUNT_ATTACH", "l2rNcMXzBNi+4+JAI39PfA=", "");
		MysqlUtils.initConfig("config","ALL_SIGNCOUNT_REPORT", "MA==", "");
		MysqlUtils.initConfig("config","BACKUP_PATH", "D:/backup", "");
		MysqlUtils.initConfig("config","BATCH_SIGN", "false", "");
		MysqlUtils.initConfig("config","MAX_SIZE", "10", "");
		MysqlUtils.initConfig("config","NEED_BACKUP", "true", "");
		MysqlUtils.initConfig("config","PDF_CREATE_MODE", "", "");
		MysqlUtils.initConfig("config","REMOTE_NEW_SIGN_COUNT", "", "最新可用签名份数--仅仅保存");
		MysqlUtils.initConfig("config","SEND_MAIL_MAX_SIZE", "10485760", "");
		MysqlUtils.initConfig("config","SHOW_DIR_MANAGE", "true", "");
		MysqlUtils.initConfig("config","SIGN_COMPANY", "", "");
		MysqlUtils.initConfig("config","SIGN_FILE_MAX", "10", "");
		MysqlUtils.initConfig("config","SIGN_FILE_MORE", "true", "");
		MysqlUtils.initConfig("config","SIGN_TYPE", "1", "1-硬");
		MysqlUtils.initConfig("config","SIGN_VALIDITY", "", "");
		MysqlUtils.initConfig("config","SING_COMPANY_ACTIVATE_FLAG", "false", "");
		MysqlUtils.initConfig("config","SVN_VERSION", "5000", "");
		MysqlUtils.initConfig("config","SYNC_DB", "false", "");
		MysqlUtils.initConfig("config","TIME_TO_CLEAR_TEMP_FILE", "", "");
		MysqlUtils.initConfig("config","UPGRADE_FINISH_MSG", "", "");
		MysqlUtils.initConfig("config","USE_VERSION", "3", "");
		MysqlUtils.initConfig("config","VERSION", "3.5", "");
		MysqlUtils.initConfig("config","YEAR_SIGNCOUNT_ATTACH", "MA==", "");
		MysqlUtils.initConfig("config","YEAR_SIGNCOUNT_REPORT", "MA==", "");
		MysqlUtils.initConfig("config","ZIP_DOWN_MAX_SIZE", "52428800", "");
		MysqlUtils.initConfig("config","VISIT_IP", "", "");
		MysqlUtils.initConfig("config","QRCODE", "false", "");
		MysqlUtils.initConfig("config","QRCODE_SERVICE_METHOD", "2", "采用be配置还是使用二维码云服务 1-be 2-qrcode");
		MysqlUtils.initConfig("config","QRCODE_HEIGTH", "60", "");
		MysqlUtils.initConfig("config","QRCODE_MATCH_NAME", "二维码", "");
		MysqlUtils.initConfig("config","QRCODE_URL", "", "");
		MysqlUtils.initConfig("config","QRCODE_WIDTH", "60", "");
		MysqlUtils.initConfig("config","QR_SERVER_IP_PORT", "192.168.1.38:8080", "");
		MysqlUtils.initConfig("config","QR_SERVER_PREFIX", "/ep", "");
		MysqlUtils.initConfig("config","QR_PDF_UPLOAD_ITF", "", "");
		MysqlUtils.initConfig("config","QR_PDF_QUERY_ITF", "", "");
		MysqlUtils.initConfig("config","QR_PDF_NEED_UPLOAD", "false", "");
		MysqlUtils.initConfig("config","SYSTEM_START_TIME", "", "系统开始使用时间");
		MysqlUtils.initConfig("config","QIFENG_FLAG", "false", "用户是否显示配置骑缝章");
		MysqlUtils.initConfig("config","SYSTEM_TYPE", "j6Mb2jOc/1C1ONF0fJR0Pw==", "系统试用版还是正式版,1-试用，2-正式");
		MysqlUtils.initConfig("config","COLLECT_SQL_FLAG", "j6Mb2jOc/1C1ONF0fJR0Pw==", "收集用户签名信息1-不收集，2-收集");
		MysqlUtils.initConfig("config","ENTERPRISEREGISTER_CONFIG_FLAG", "j6Mb2jOc/1C1ONF0fJR0Pw==", "企业注册配置是否显示1-不显示：j6Mb2jOc/1C1ONF0fJR0Pw==;2-显示：x170dD1Y0+PAmtKCQwHq8g==");	
		MysqlUtils.initConfig("config","REPORTMERGE_FLAG", "false", "用户是否显示配置封面和尾页");	
		MysqlUtils.initConfig("config","SELECT_CREDENTIALS_FLAG", "false", "用户是否可以选择资质章--目前用于佛山计量局");
		MysqlUtils.initConfig("config","MERGE_MAX_COUNT", "5", "每次最多合并文档个数");
		MysqlUtils.initConfig("config","FINGER_KEY_FLAG", "false", "需要指纹key");
		MysqlUtils.initConfig("config","HAND_BAG_FLAG", "false", "需要手写板");
		MysqlUtils.initConfig("config","HAND_WRITE_QR_URL", "www.quceba.com", "手写签名二维码IP");
		MysqlUtils.initConfig("config","IS_SERVER_SIGN", "false", "判断是否用服务器签名");
		MysqlUtils.initConfig("config","HAND_WRITE_SIGN", "false", "判断是否需手写签名");
		MysqlUtils.initConfig("config","SYSTEM_FEE_TYPE", "1", "系统收费类型");
		MysqlUtils.initConfig("config","SYSTEM_DEFAULTS_LANGUAGE", "zh_CN", "系统默认语言");
		MysqlUtils.initConfig("config","SMT_SYSTEM_DEFAULTS_LANGUAGE", "zh_CN", "SMT默认语言");
		MysqlUtils.initConfig("config","SYSTEM_PRODUCT_NAME", "IDS", "系统软件名称");
		MysqlUtils.initConfig("config","IDS_SERVER_PORT", "8080", "项目访问端口");
		MysqlUtils.initConfig("config","NETTY_SERVER_IP", "192.168.0.141", "项目访问IP");
		MysqlUtils.initConfig("config","PATTER_LOGO_FLAG", "0", "登录页Logo");
		MysqlUtils.initConfig("config","HIDDEN_EMAIL_FLAG", "0", "邮箱开关");
		MysqlUtils.initConfig("config","LOGIN_TYPE", "0", "登录方式");
		MysqlUtils.initConfig("config","NETTY_SERVER_PORT", "10029", "");
		MysqlUtils.initConfig("config","FILE_STORAGE_FALG", "2", "文件存储管理是否标识 1.启动  2 未启动");
		MysqlUtils.initConfig("config","FILE_DEFAULT_STORAGE_PATH_FLAG", "0", "文件存储默认插入的地址  默认地址有没有 修改  1.修改  0 未修改");
		MysqlUtils.initConfig("config","PDF_TRANSFORM_URL", "localhost:8383/fileToPdf.asmx/fileToPdf", "http转pdf 请求地址");
		MysqlUtils.initConfig("config","PDF_TRANSFORM_SOCKET_PORT", "18698", "pdf转换通信的服务器端端口");
		MysqlUtils.initConfig("config","LICENSE_IMPORT_TIME", "", "license导入时间");
		MysqlUtils.initConfig("config","BE_KEY_FLAG", "1", "0 客户端签名  1 使用Key公共证书，及服务器Key(服务端签名)");
		MysqlUtils.initConfig("config","AD_SERVER_NET_URL", "http://192.168.0.121:90/index.aspx", "获取本地域名的请求地址");
		MysqlUtils.initConfig("config","WATERMARK_OVERCONTENT_FLAG", "false", "水印置上标识");
		MysqlUtils.initConfig("config","SHCA_KEY_FLAG", "0", "0-默认是上海，1-任意公司Key都可以用");
		MysqlUtils.initConfig("config","AUTOMATIC_SIGNATURE_FLAG", "0", "签章自动匹配 0--关闭  1---开启");
		MysqlUtils.initConfig("config","ENCROPYT_TO_PDF", "true", "签章属性是否更改开关 0--关闭  1---开启");
		getUpgraeSql();
		updateConfig("3.5.6","6209");
	}
	
	/**
	 * 保证当前版本号 和 使用版本号 一致
	 * @param version
	 * @param svn_version
	 * @throws Exception
	 */
	public static void updateConfig(String version,String svn_version) throws Exception{
		if(!StringUtils.equals(svn_version, "7862")){
			MysqlUtils.updateConfig("config","SVN_VERSION", "7862");
		}

		if(!StringUtils.equals(version, "3.5.7")){
			MysqlUtils.updateConfig("config","VERSION", "3.5.7");
		}
	}

	/**
	 * 对于数据库升级
	 */
	public static void getUpgraeSql(){
		sqlStatements("INSERT INTO `config`(`KEY`,`VALUE`,`REMARK`) VALUES ('KEY_MULTI_LABLE_FLAG', 'false', 'key模式是否多签名开关true --打开多签  false--关闭多签')");
	}

	/**
	 * 执行sql脚本
	 * @param sql
	 */
	public static void sqlStatements(String sql){
		//交由cma处理 目前common还未提供接口
	}

	/**
	 * 增加字段
	 * @param databaseName
	 * @param fieldAttributes
	 */
	public static void addDatabaseFields(String databaseName,String fieldAttributes){
		//交由cma处理
	}
}
